package com.heo.sso.client.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 刘康
 * @Date 2020-11-03 16:50
 * @Description
 * @Revision
 **/
@Slf4j
public class LogoutFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        // 获取退出标识符
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        String ticket = req.getParameter("ticket");
        if (ticket == null) {
            resp.sendRedirect("/");
            return;
        }
        String token = LoginFilter.redis.remove(ticket);
        LoginFilter.redis.remove(token);
        //开始注销
        log.info("注销系统");
        log.info("~~~~~~~~~");
        return;
    }
}
